//
//  UIButton+JXE.swift
//  JXUtilsDemo
//
//  Created by ccks on 2018/11/28.
//  Copyright © 2018 Zhu Jinxin. All rights reserved.
//

import Foundation
import UIKit

extension UIButton {
    
    convenience init(target:Any,Action:Selector,Title : String?,imageName:String?,size:CGSize){
        
        self.init(frame:.zero)
        
        if #available(iOS 11.0, *){
            self.widthAnchor.constraint(equalToConstant: size.width).isActive = true
            self.heightAnchor.constraint(equalToConstant:size.height).isActive = true
        }else{
            self.frame.size.width = size.width
            self.frame.size.height = size.height
        }
        
        self.setTitle(Title, for: .normal)
        self.setImage(UIImage(named: imageName ?? ""), for: .normal)
        self.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        self.setTitleColor(UIColor.black, for: .normal)
        self.addTarget(target
            , action: Action
            , for: .touchUpInside)
        
    }

    
}

